home *** CD-ROM | disk | FTP | other *** search
-
- XDEF NumToStr
-
- ; Args:
- ; A0 Pointer to space for the converted ASCII number. (11 bytes)
- ; D0 32 bit number to convert.
-
- ; Returns:
- ; A0 Pointer to a ASCII number string.
- ; D0 Length of the string.
-
- ; A1 & D1 will be trashed.
-
- ; I have a feeling this routine could be optimized by making it test if
- ; 8xNumber can be sub'ed, then 4xNumber and after that 2xNumber, and finally
- ; 1xNumber. This way there would be a max of four passes, before it was 10.
- ; It would be 4 passes against average 5 passes, so a 20% speedup?
-
- ; move.l #1000000000,d0
- ; move.l #space,a0
- ; bsr NumToStr
- ; rts
-
- ;space:
- ; ds.b 11
-
- ; even
-
- NumToStr:
- clr.l d1
- move.l a0,a1
- tst.l d0
- beq NumToStr_Zero
-
- NumToStr1:
- cmp.l #1000000000,d0
- bcc onegig
- move.b d1,(a0)
- add.b #"0",(a0)+
- clr.l d1
-
- NumToStr2:
- cmp.l #100000000,d0
- bcc one100meg
- move.b d1,(a0)
- add.b #"0",(a0)+
- clr.l d1
-
- NumToStr3:
- cmp.l #10000000,d0
- bcc one10meg
- move.b d1,(a0)
- add.b #"0",(a0)+
- clr.l d1
-
- NumToStr4:
- cmp.l #1000000,d0
- bcc onemeg
- move.b d1,(a0)
- add.b #"0",(a0)+
- clr.l d1
-
- NumToStr5:
- cmp.l #100000,d0
- bcc one100k
- move.b d1,(a0)
- add.b #"0",(a0)+
- clr.l d1
-
- NumToStr6:
-
- divu #10000,d0
- move.b d0,(a0)
- add.b #48,(a0)+
- move.w #0,d0
-
- swap d0
-
- divu #1000,d0
- move.b d0,(a0)
- add.b #48,(a0)+
- move.w #0,d0
-
- swap d0
-
- divu #100,d0
- move.b d0,(a0)
- add.b #48,(a0)+
- move.w #0,d0
-
- swap d0
-
- divu #10,d0
- move.b d0,(a0)
- add.b #48,(a0)+
-
- swap d0
-
- move.b d0,(a0)
- add.b #48,(a0)+
-
- clr.b (a0) ; Make it a string.
- move.l a1,a0
-
- NumToStr11:
- cmp.b #"0",(a0)
- beq NumToStr_clearZero
-
- move.l a1,a0
- moveq #10,d0
-
- NumToStr12:
- cmp.b #" ",(a0)
- beq NumToStr_sublen
- rts
-
- NumToStr_sublen:
- subq.l #1,d0
- addq.l #1,a0
- bra NumToStr12
-
- NumToStr_clearZero:
- move.b #" ",(a0)+
- bra NumToStr11
-
- onegig:
- sub.l #1000000000,d0
- addq.l #1,d1
- bra NumToStr1
-
- one100meg:
- sub.l #100000000,d0
- addq.l #1,d1
- bra NumToStr2
-
- one10meg:
- sub.l #10000000,d0
- addq.l #1,d1
- bra NumToStr3
-
- onemeg:
- sub.l #1000000,d0
- addq.l #1,d1
- bra NumToStr4
-
- one100k:
- sub.l #100000,d0
- addq.l #1,d1
- bra NumToStr5
-
- NumToStr_Zero:
- move.b #"0",(a0)
- clr.b 1(a0)
- moveq #1,d0
- rts
-